<script setup lang="ts">
import {SELL_STATUS} from "../../../const/common";
import {EXAMINE_STATUS} from "../../../const/Maps";

definePageMeta({
  layout:'admin',
  title:'我的发布的一口价列表'
});
const form=reactive({
  limit:20,
  page:1,
  name:'',//模糊搜索-域名
});
const {data:list,refresh}=await useServerGet('/fp/getDomainList',form)
const modifyPrice=(row:any)=>{
  ElMessageBox.prompt('请输入新的价格','提示',{
    confirmButtonText:'确定',
    cancelButtonText:'取消',
    //1.31
    inputPattern:/^\d+(\.\d{1,2})?$/,
    inputErrorMessage:'请输入数字',
    inputValue:row.price,
    inputType:'number',
    center:true,
  }).then(async ({value})=>{
    const {code,data}=await usePost('/fp/updateGoods',{id:row.id,price:value})
    if(code===200){
      ElMessage.success('修改成功')
      refresh&&refresh();
    }
  })
}
const cancel=(row)=>{
  ElMessageBox.confirm('确定取消该域名一口价吗？','提示',{
    confirmButtonText:'确定',
    cancelButtonText:'取消',
    type:'warning'
  }).then(async ()=>{
    const {code}=await usePost('/fp/cancel',{id:row.id})
    if(code===200){
      ElMessage.success('取消成功')
      refresh&&refresh();
    }
  })

}
const search=()=>{
  refresh&&refresh();
}
</script>

<template>
<div id="container">
  <el-affix :offset="124" target="#container">
    <el-card>
      <div class="flex">
        <div class="w-52 mr-2">
          <el-input placeholder="请输入域名" v-model="form.name" class="w-40" clearable></el-input>
        </div>
        <div class="w-20">
          <el-button type="primary" @click="search">搜索</el-button>
        </div>
      </div>
    </el-card>
  </el-affix>
  <el-card class="mt-4">
    <el-table :data="list.data.list" :header-cell-style="{'text-align':'center'}" :cell-style="{'text-align':'center'}" class="h-[620px] overflow-auto">
      <el-table-column prop="id" label="ID"></el-table-column>
      <el-table-column prop="domain" label="域名" min-width="150"></el-table-column>
      <el-table-column prop="price" label="价格"></el-table-column>
<!--      <el-table-column prop="user_phone" label="手机号"></el-table-column>-->
<!--      <el-table-column prop="synopsis" label="域名简介"></el-table-column>-->
      <el-table-column prop="register_time" label="注册时间"></el-table-column>
      <el-table-column prop="expiration_time" label="到期时间"></el-table-column>
      <el-table-column prop="state" label="状态">
        <template #default="{row}">
          {{SELL_STATUS[row.state]}}
        </template>
      </el-table-column>
      <el-table-column prop="state" label="审核状态">
        <template #default="{row}">
          {{EXAMINE_STATUS[row.examine_status]}}
        </template>
      </el-table-column>
      <el-table-column prop="updated_at" label="更新时间"></el-table-column>
      <el-table-column prop="created_at" label="创建时间"></el-table-column>
      <el-table-column label="操作">
        <template #default="{row}">
          <div class="flex justify-center">
            <el-button type="danger" class="ml-1" @click="modifyPrice(row)" v-if="row.state!=2">修改价格</el-button>
            <el-button @click="cancel(row)">取消</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <MyPage v-model:page="form.page" v-model:perpage="form.limit" v-model:total="list.data.total" @change="refresh"></MyPage>
  </el-card>
</div>
</template>

<style scoped lang="scss">

</style>